package com.example.xuanmei.user.controller;

import com.example.xuanmei.common.dto.ApiResponse;
import com.example.xuanmei.user.dto.LoginRequest;
import com.example.xuanmei.user.dto.RegisterRequest;
import com.example.xuanmei.user.dto.UserDto;
import com.example.xuanmei.user.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 用户控制器
 */
@RestController
@RequestMapping("/api/user")
@RequiredArgsConstructor
@CrossOrigin
public class UserController {
    private final UserService userService;
    
    @PostMapping("/register")
    public ApiResponse<Map<String, Object>> register(@RequestBody RegisterRequest request) {
        return userService.register(request);
    }
    
    @PostMapping("/login")
    public ApiResponse<Map<String, Object>> login(@RequestBody LoginRequest request) {
        return userService.login(request);
    }
    
    @GetMapping("/info/{userId}")
    public ApiResponse<UserDto> getUserInfo(@PathVariable Long userId) {
        return userService.getUserInfo(userId);
    }
}
